package com.ruoyi.community.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.community.mapper.OwnerNoticeMapper;
import com.ruoyi.community.domain.OwnerNotice;
import com.ruoyi.community.service.IOwnerNoticeService;

/**
 * 信息公告Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-09-26
 */
@Service
public class OwnerNoticeServiceImpl implements IOwnerNoticeService 
{
    @Autowired
    private OwnerNoticeMapper ownerNoticeMapper;

    /**
     * 查询信息公告
     * 
     * @param noticeId 信息公告ID
     * @return 信息公告
     */
    @Override
    public OwnerNotice selectOwnerNoticeById(String noticeId)
    {
        OwnerNotice resultOwnerNotice = ownerNoticeMapper.selectOwnerNoticeById(noticeId);
        Long viewNumber = resultOwnerNotice.getViewNumber() + 1;
        resultOwnerNotice.setViewNumber(viewNumber);
        updateOwnerNotice(resultOwnerNotice);
        return resultOwnerNotice;
//        return ownerNoticeMapper.selectOwnerNoticeById(noticeId);
    }

    /**
     * 查询信息公告列表
     * 
     * @param ownerNotice 信息公告
     * @return 信息公告
     */
    @Override
    public List<OwnerNotice> selectOwnerNoticeList(OwnerNotice ownerNotice)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        ownerNotice.setCommunityId(Long.valueOf(loginUser.getCommunityId()));
        return ownerNoticeMapper.selectOwnerNoticeList(ownerNotice);
    }

    /**
     * 新增信息公告
     * 
     * @param ownerNotice 信息公告
     * @return 结果
     */
    @Override
    public int insertOwnerNotice(OwnerNotice ownerNotice)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        ownerNotice.setAuthor(loginUser.getUsername());
        ownerNotice.setCommunityId(Long.valueOf(loginUser.getCommunityId()));
        return ownerNoticeMapper.insertOwnerNotice(ownerNotice);
    }

    /**
     * 修改信息公告
     * 
     * @param ownerNotice 信息公告
     * @return 结果
     */
    @Override
    public int updateOwnerNotice(OwnerNotice ownerNotice)
    {
        return ownerNoticeMapper.updateOwnerNotice(ownerNotice);
    }

    /**
     * 批量删除信息公告
     * 
     * @param noticeIds 需要删除的信息公告ID
     * @return 结果
     */
    @Override
    public int deleteOwnerNoticeByIds(String[] noticeIds)
    {
        return ownerNoticeMapper.deleteOwnerNoticeByIds(noticeIds);
    }

    /**
     * 删除信息公告信息
     * 
     * @param noticeId 信息公告ID
     * @return 结果
     */
    @Override
    public int deleteOwnerNoticeById(String noticeId)
    {
        return ownerNoticeMapper.deleteOwnerNoticeById(noticeId);
    }
}
